    <?php foreach ($entity as $e): ?>
        <div class="ibox float-e-margins animated fadeInDown" id="main_windowv">
            <div class="ibox-title" style="border: none;">
                <h5 style="color: #00afef"><i>View</i></h5>
            </div>
            <div class="ibox-content">
                <form class="form-horizontal" id="entity_form_v">
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Entity Type</label>
                        <div class="col-lg-5">
                            <input type="hidden" id="e_type" value="<?php echo $e->entity_type; ?>">
                            <input readonly value="<?php echo $e->meaning; ?>" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group organization">
                        <label class="col-lg-4 control-label">Entity Name</label>
                        <div class="col-lg-5">
                            <input readonly  type="text" value="<?php echo $e->entity_name; ?>" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Tax Registration Number</label>
                        <div class="col-lg-5">
                            <input readonly value="<?php echo $e->tax_reg_num; ?>" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group person">
                        <label class="col-lg-4 control-label">Title</label>
                        <div class="col-lg-5">
                            <input readonly  type="text" value="<?php echo $e->title; ?>" class="form-control">
                        </div>
                    </div>
                    <div class="form-group person">
                        <label class="col-lg-4 control-label">Last Name</label>
                        <div class="col-lg-5">
                            <input readonly  type="text" value="<?php echo $e->last_name; ?>" class="form-control">
                        </div>
                    </div>
                    <div class="form-group person">
                        <label class="col-lg-4 control-label">Middle Name</label>
                        <div class="col-lg-5">
                            <input readonly  type="text" value="<?php echo $e->middle_name; ?>" class="form-control">
                        </div>
                    </div>
                    <div class="form-group person">
                        <label class="col-lg-4 control-label">First Name</label>
                        <div class="col-lg-5">
                            <input readonly  type="text" value="<?php echo $e->first_name; ?>" class="form-control">
                        </div>
                    </div>
                    <div class="form-group person" id="data_3">
                        <label class="col-lg-4 control-label">Birthday</label>
                        <div class="col-lg-5">
                            <input readonly value="<?php echo $e->date_of_birth; ?>" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Enable</label>
                        <div class="col-lg-1">
                            <div class="state icheckbox_square-green <?php echo $e->enable_flag == 'Y' ? 'checked' : ''; ?>"></div>
                        </div>
                    </div>
                    </form>
                </div>
            <?php endforeach;?>
                <div class="ibox-title" style="border: none;">
                    <h5><b>Main Address</b></h5>
                </div>
                <div class="ibox-content">
                <?php if (empty($addr)) {echo "<h5>Empty Address<h5>";}
?>
                <?php foreach ($addr as $a): ?>
                    <form class="form-horizontal" id="entity_address_form">
                        <input readonly  type="hidden" name="addr_code" value="MAIN">
                        <div class="form-group">
                            <label class="col-lg-4 control-label">Address 1</label>
                            <div class="col-lg-5">
                                <input readonly value="<?php echo $a->address_1; ?>" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-4 control-label">Address 2</label>
                            <div class="col-lg-5">
                                <input readonly  value="<?php echo $a->address_2; ?>" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-4 control-label">Address 3</label>
                            <div class="col-lg-5">
                                <input readonly  value="<?php echo $a->address_3; ?>" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-4 control-label">City / Town</label>
                            <div class="col-lg-5">
                                <input readonly value="<?php echo $a->city_town; ?>" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-4 control-label">Postal Code</label>
                            <div class="col-lg-5">
                                <input readonly value="<?php echo $a->postal_code; ?>" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-4 control-label">Province / State</label>
                            <div class="col-lg-5">
                                <input readonly value="<?php echo $a->state_province; ?>" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-4 control-label">Country</label>
                            <div class="col-lg-5">
<?php foreach ($country as $c) {
	$country;
	if ($a->country == $c->country_code) {
		$country = $c->country_name;
	}
	if ($a->country == '0') {
		$country = 'No Country';
	}
}
?>
                             <input readonly value="<?php echo $country; ?>" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-4 control-label">Phone 1</label>
                            <div class="col-lg-5">
                                <input readonly value="<?php echo $a->phone_1; ?>" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-4 control-label">Phone 2</label>
                            <div class="col-lg-5">
                                <input readonly value="<?php echo $a->phone_2; ?>" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-4 control-label">Phone 3</label>
                            <div class="col-lg-5">
                                <input readonly value="<?php echo $a->phone_3; ?>" type="text" class="form-control">
                            </div>
                        </div>
                        <?php foreach ($zone1 as $key): ?>
                        <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>;">
                                <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                            <?php endforeach;?>
                            <div class="col-lg-5">
                                <input readonly type="text" name="zone_1" value="<?php echo $a->zone_1; ?>" class="form-control">
                            </div>
                        </div>
                         <?php foreach ($zone2 as $key): ?>
                        <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>;">
                                <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                            <?php endforeach;?>
                            <div class="col-lg-5">
                                <input readonly type="text" name="zone_2" value="<?php echo $a->zone_2; ?>" class="form-control">
                            </div>
                        </div>
                        <?php foreach ($zone3 as $key): ?>
                        <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>;">
                                <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                            <?php endforeach;?>
                            <div class="col-lg-5">
                                <input readonly type="text" name="zone_3" value="<?php echo $a->zone_1; ?>" class="form-control">
                            </div>
                        </div>
                        < <?php foreach ($zone4 as $key): ?>
                        <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>;">
                                <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                            <?php endforeach;?>
                            <div class="col-lg-5">
                                <input readonly type="text" name="zone_1" value="<?php echo $a->zone_4; ?>" class="form-control">
                            </div>
                        </div>
                         <?php foreach ($zone5 as $key): ?>
                        <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>;">
                                <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                            <?php endforeach;?>
                            <div class="col-lg-5">
                                <input readonly type="text" name="zone_1" value="<?php echo $a->zone_5; ?>" class="form-control">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="ibox-content">
                </div>
                <div class="ibox-title" style="border: none;">
                        <h5><i>List of Other Address's</i></h5>
                    </div>
                    <table class="table">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th>Address Code</th>
                                <th>Address 1</th>
                                <th>Enable</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php $count2 = 1;?>
                        <?php foreach ($addr2 as $a2): ?>
                            <tr <?php echo $a2->addr_code == 'MAIN' ? 'style="display: none;"' : ''; ?> <?php echo $a2->addr_code == 'MAIN' ? $count2 = $count2 - 1 : ''; ?>>
                                <td><?php echo $count2; ?></td>
                                <td><?php echo $a2->addr_code; ?></td>
                                <td><?php echo $a2->address_1; ?></td>
                                <td align="center"><div class="state icheckbox_square-green <?php echo $a2->enable_flag == 'Y' ? 'checked' : ''; ?>"></div></td>
                                <td style="display: none;" id="addr_id"><?php echo $a2->address_id; ?></td>
                                <td><button class='btn btn-sm btn-outline btn-info btn-xs view-modal-addr'><i class="fa fa-file-text-o fa-lg"></i></button></td>
                            </tr>
                        <?php $count2++;?>
                        <?php endforeach;?>
                        </tbody>
                    </table>
                <div class="ibox-title" style="border: none;">
                    <h5><i>List of Other Account's</i></h5>
                </div>
                <table class="table">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Account Name</th>
                            <th>Account Type</th>
                            <th>Status</th>
                            <th>Enable</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $count = 1;?>
                        <?php foreach ($acct2 as $ac): ?>
                            <tr>
                                <td><?php echo $count; ?></td>
                                <td><?php echo $ac->acct_name; ?></td>
                                <td><?php echo $ac->meaning; ?></td>
                                 <td><?php echo $ac->status_meaning; ?></td>
                                <td align="center"><div class="state icheckbox_square-green <?php echo $ac->enable_flag == 'Y' ? 'checked' : ''; ?>"></div></td>
                                <td style="display: none;" id="acct_addr"><?php echo $ac->acct_addr; ?></td>
                                <td style="display: none;" id="acct_id"><?php echo $ac->account_id; ?></td>
                                <td><button class='btn btn-sm btn-outline btn-info btn-xs view-modal-acc'><i class="fa fa-file-text-o fa-lg"></i></button></td>
                            </tr>
                        <?php $count++;?>
                        <?php endforeach;?>
                        </tbody>
                </table>
            </div>
        </div>
    </div><!-- iBox -->
    <?php endforeach;?>
    <div class="ibox float-e-margin animated fadeInDown" id="address_windowv" style="display:none;">
        <div class="ibox-title" style="border: none;">
            <h5 style="color: #00afef"><i>Address</i></h5>
            <div class="ibox-tools">
                <button type="button" class="btn btn-white cancel-btn-tab" id="address_close_btns">Close</button>
            </div>
        </div>
        <div class="ibox-content" id="entity_address_form_2_v">
            <form class="form-horizontal" >
                <div class="form-group">
                    <label class="col-lg-4 control-label">Address Code</label>
                    <div class="col-lg-6">
                        <input readonly id="addr_code"  type="text" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Address 1</label>
                    <div class="col-lg-6">
                        <input readonly id="addr_1" type="text" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Address 2</label>
                    <div class="col-lg-6">
                        <input readonly id="addr_2" type="text" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Address 3</label>
                    <div class="col-lg-6">
                        <input readonly id="addr_3" type="text" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">City / Town</label>
                    <div class="col-lg-6">
                        <input readonly id="citytown" type="text" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Postal Code</label>
                    <div class="col-lg-6">
                        <input readonly id="postalcode" type="text" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Province / State</label>
                    <div class="col-lg-6">
                        <input readonly id="provincestate" type="text" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Country</label>
                    <div class="col-lg-6">
                        <input readonly id="country_v" type="text" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Phone 1</label>
                    <div class="col-lg-6">
                        <input readonly id="phone1" type="text" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Phone 2</label>
                    <div class="col-lg-6">
                        <input readonly id="phone2" type="text" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Phone 3</label>
                    <div class="col-lg-6">
                        <input readonly id="phone3" type="text" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Purpose</label>
                    <div class="col-lg-6">
                        <input readonly id="purpose_v" type="text" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Enable</label>
                    <div class="col-lg-1">
                        <div id="enable_flag_v" class="state icheckbox_square-green"></div>
                    </div>
                </div>
                <h4 id="overview" class="page-header">Address Zone</h4>
                 <?php foreach ($zone1 as $key): ?>
                <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>;">
                        <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                    <?php endforeach;?>
                    <div class="col-lg-7">
                        <input readonly type="text" id="zn_1"class="form-control">
                    </div>
                </div>
               <?php foreach ($zone2 as $key): ?>
                <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>;">
                        <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                    <?php endforeach;?>
                    <div class="col-lg-7">
                        <input readonly type="text" id="zn_2"class="form-control">
                    </div>
                </div>
                <?php foreach ($zone3 as $key): ?>
                <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>;">
                        <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                    <?php endforeach;?>
                    <div class="col-lg-7">
                        <input readonly type="text" id="zn_3"class="form-control">
                    </div>
                </div>
               <?php foreach ($zone4 as $key): ?>
                <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>;">
                        <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                    <?php endforeach;?>
                    <div class="col-lg-7">
                        <input readonly type="text" id="zn_4"class="form-control">
                    </div>
                </div>
                <?php foreach ($zone5 as $key): ?>
                <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>;">
                        <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                    <?php endforeach;?>
                    <div class="col-lg-7">
                        <input readonly type="text" id="zn_5"class="form-control">
                    </div>
                </div>
            </form>
        </div>
    </div><!-- END OF MODAL-->
    <div class="ibox float-e-margins animated fadeInDown" id="account_windowv" style='display:none;'>
            <div class="ibox-title" style="border: none;">
                <h5 style="color: #00afef"><i>Account</i></h5>
                <div class="ibox-tools">
                     <button type="button" class="btn btn-white cancel-btn-tab" id="account_close_btn">Close</button>
                </div>
            </div>
            <div id="loading_account" class="spiner-example" style="display: none;">
                <div class="sk-spinner sk-spinner-rotating-plane"></div>
            </div>
            <div class="ibox-content" id="view_acc_modal_body">
                <form class="form-horizontal" id="account_form_view">
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Entity Name</label>
                        <div class="col-lg-6">
                            <input  readonly type="text" id="entityname" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Account Number</label>
                        <div class="col-lg-6">
                            <input readonly  type="text" id="acctnum" class="form-control text-right">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Account Name</label>
                        <div class="col-lg-6">
                            <input readonly  type="text" id="acctname" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Account Type</label>
                        <div class="col-lg-6">
                            <input readonly  type="text" id="accttype" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Attention to</label>
                        <div class="col-lg-6">
                            <input readonly  type="text" id="attentionto" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Account Address</label>
                        <div class="col-lg-6">
                            <input readonly  type="text" id="acctaddr" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Bill To Address</label>
                        <div class="col-lg-6">
                            <input readonly  type="text" id="billtoaddr" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Active Date From</label>
                        <div class="col-lg-6">
                            <input readonly  type="text" id="activestart" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Active Date To</label>
                        <div class="col-lg-6">
                            <input readonly  type="text" id="activeend" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Meter Sequence</label>
                        <div class="col-lg-6">
                            <input readonly type="input" name="meter_seq" value="" id="meterseq" class="form-control text-right">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Status</label>
                        <div class="col-lg-6">
                            <input readonly  type="text" id="status_v" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Enable</label>
                        <div class="col-lg-1">
                            <div id="enable_flag_v2" class="state icheckbox_square-green checked"></div>
                        </div>
                    </div>
                </form>
                <form class="form-horizontal" id="zone_form">
                    <h4 id="overview" class="page-header">Address Zone <small></small></h4>
                     <?php foreach ($zone1 as $key): ?>
                <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>">
                        <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                    <?php endforeach;?>
                        <div class="col-lg-7">
                            <input readonly  type="text" id="z1" class="form-control">
                        </div>
                    </div>
                     <?php foreach ($zone2 as $key): ?>
                <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>">
                        <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                    <?php endforeach;?>
                        <div class="col-lg-7">
                            <input readonly  type="text" id="z2"  class="form-control">
                        </div>
                    </div>
                     <?php foreach ($zone3 as $key): ?>
                <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>">
                        <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                    <?php endforeach;?>
                        <div class="col-lg-7">
                            <input readonly  type="text" id="z3"  class="form-control">
                        </div>
                    </div>
                    <?php foreach ($zone4 as $key): ?>
                <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>">
                        <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                    <?php endforeach;?>
                        <div class="col-lg-7">
                            <input readonly  type="text" id="z4"  class="form-control">
                        </div>
                    </div>
                    <?php foreach ($zone5 as $key): ?>
                <div class="form-group" style="display: <?php echo ($key->enable_flag == 'N' ? 'none' : ''); ?>">
                        <label class="col-lg-4 control-label"><?php echo $key->field_label; ?></label>
                    <?php endforeach;?>
                        <div class="col-lg-7">
                            <input readonly  type="text" id="z5" class="form-control">
                        </div>
                    </div>
                </form>
            </div>
            <div class="ibox-title" style="border: none;">
                <h5><i>Charge List</i></h5>
            </div>
                <form id="chglist_form_e" class="form-horizontal">
                    <table class="table" width="100%">
                        <thead>
                            <tr>
                                <th>Charge List</th>
                                <th>Start Date</th>
                                <th>End Date</th>
                                <th>Enable</th>
                            </tr>
                        </thead>
                        <tbody id="charglist_tbl">
                        </tbody>
                    </table>
                </form>
            <div class="ibox-title" style="border: none;">
                <h5><i>List of Other Device's</i></h5>
            </div>
            <table class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Device ID</th>
                        <th>Model Nubmer</th>
                        <th>Serial Number</th>
                        <th>Status</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody id="device_table">
                </tbody>
            </table>
        </div>
    </div><!-- END OF MODAL-->
    <div class="ibox float-e-margins animated fadeInDown" id="device_windowv" style='display:none;'>
        <div class="ibox-title" style="border: none;">
            <h5 style="color: #00afef"><i>Device</i></h5>
            <div class="ibox-tools">
                <button type="button" class="btn btn-white cancel-btn-tab" id="device_close_btn">Close</button>
            </div>
        </div>
        <div class="ibox-content" id="view_dev_modal_body">
            <div style="display: none;" class="spiner-example">
                <div class="sk-spinner sk-spinner-rotating-plane"></div>
            </div>
           <form class="form-horizontal" id="device_form_v">
                <input type="hidden" name="account_id">
                <div class="form-group">
                    <label class="col-lg-4 control-label">Item Number</label>
                    <div class="col-lg-7">
                        <input readonly type="text" name="item_num" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Device Type</label>
                    <div class="col-lg-7">
                        <input readonly type="text" name="dev_type" class="form-control">
                    </div>
                </div>
                 <div class="form-group">
                    <label class="col-lg-4 control-label">Model Number</label>
                    <div class="col-lg-7">
                        <input readonly type="text" name="model_number" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Serial Number</label>
                    <div class="col-lg-7">
                        <input readonly type="text" name="serial_number" class="form-control">
                    </div>
                </div>
                 <div class="form-group">
                    <label class="col-lg-4 control-label">Device ID</label>
                    <div class="col-lg-7">
                        <input readonly   type="text" name="dev_id" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Installation Date</label>
                    <div class="col-lg-7">
                        <input readonly type="text" name="install_date" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Warranty Period</label>
                    <div class="col-lg-7">
                        <input readonly type="text" name="warranty_per" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Initial Reading</label>
                    <div class="col-lg-7">
                        <input readonly type="text" name="initial_read" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Last Reading</label>
                    <div class="col-lg-7">
                        <input readonly type="text" name="last_read" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Status</label>
                    <div class="col-lg-7">
                        <input readonly type="text" name="status" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-4 control-label">Device Remarks</label>
                    <div class="col-lg-7">
                        <input readonly type="text" name="dev_remarks" class="form-control">
                    </div>
                </div>
            </form>
        </div>
    </div><!-- END OF MODAL-->

    <script type="text/javascript">
            $(document).ready(function() {
                etype($('#e_type').val());
                function etype(type){
                    if(type == "ORG"){
                        $('#entity_form_v .form-group.organization').show();
                        $('#entity_form_v .form-group.person').hide();
                    }else{
                        $('#entity_form_v .form-group.person').show();
                        $('#entity_form_v .form-group.organization').hide();
                    }
                }

                $('.i-checks').iCheck({
                    checkboxClass: 'icheckbox_square-green',
                    radioClass: 'iradio_square-green'
                });

                $('#address_close_btns').click(function(){
                    $('#address_windowv').hide();
                    $('#main_windowv').show();
                });
                $('#account_close_btn').click(function(){
                    $('#account_windowv').hide();
                    $('#main_windowv').show();
                });
                $('#device_close_btn').click(function(){
                    $('#device_windowv').hide();
                    $('#account_windowv').show();
                });

                $('.btn.btn-sm.btn-outline.btn-info.btn-xs.view-modal-addr').click(function(){
                    var addr_id = $(this).closest('tr').children('#addr_id').text();
                    $.ajax({
                        url: "<?php echo base_url($this->session->userdata('forajax') . '/getAddress'); ?>",
                        method:'post',
                        data: { 'entity_id': sessionStorage.entity_id_v, 'address_id': addr_id },
                        dataType:'json',
                        success: function (data) {
                            if(data[0].enable_flag == 'Y'){
                                $('#entity_address_form_2_v #enable_flag_v').addClass('checked');
                            }else{
                                $('#entity_address_form_2_v #enable_flag_v').removeClass('checked');
                            }
                            $('#entity_address_form_2_v #addr_code').val(data[0].addr_code);
                            $('#entity_address_form_2_v #addr_1').val(data[0].address_1);
                            $('#entity_address_form_2_v #addr_2').val(data[0].address_2);
                            $('#entity_address_form_2_v #addr_3').val(data[0].address_3);
                            $('#entity_address_form_2_v #citytown').val(data[0].city_town);
                            $('#entity_address_form_2_v #country_v').val(data[0].country);
                            $('#entity_address_form_2_v #purpose_v').val(data[0].purpose);
                            $('#entity_address_form_2_v #provincestate').val(data[0].state_province);
                            $('#entity_address_form_2_v #postalcode').val(data[0].postal_code);
                            $('#entity_address_form_2_v #zn_1').val(data[0].zone_1);
                            $('#entity_address_form_2_v #zn_2').val(data[0].zone_2);
                            $('#entity_address_form_2_v #zn_3').val(data[0].zone_3);
                            $('#entity_address_form_2_v #zn_4').val(data[0].zone_4);
                            $('#entity_address_form_2_v #zn_5').val(data[0].zone_5);
                            $('#entity_address_form_2_v #phone1').val(data[0].phone_1);
                            $('#entity_address_form_2_v #phone2').val(data[0].phone_2);
                            $('#entity_address_form_2_v #phone3').val(data[0].phone_3);
                            $('#address_windowv').show();
                            $('#main_windowv').hide();
                        },
                        complete: function() {
                            $('#loading-icon-addr').hide();
                        },
                        beforeSend: function(){
                            $('#loading-icon-addr').show();
                        }
                    });
                });

                $('.btn.btn-sm.btn-outline.btn-info.btn-xs.view-modal-acc').click(function(){
                    $('#account_windowv').show();
                    $('#main_windowv').hide();
                    var acct_id = $(this).closest('tr').children('#acct_id').text();
                    var acct_addr = $(this).closest('tr').children('#acct_addr').text();
                    $.ajax({
                        url: "<?php echo base_url($this->session->userdata('forajax') . '/getAccount'); ?>",
                        method:'post',
                        data: { 'entity_id': sessionStorage.entity_id_v, 'account_id': acct_id, 'acct_addr': acct_addr },
                        dataType:'json',
                        success: function (data) {
                            if(data[0].enable_flag == 'Y'){
                                $('#account_form_view #enable_flag_v2').addClass('checked');
                            }else{
                                $('#account_form_view #enable_flag_v2').removeClass('checked');
                            }
                            $('#account_form_view #entityname').val(data[0].entity_name);
                            $('#account_form_view #acctaddr').val(data[0].acct_addr_meaning);
                            $('#account_form_view #accttype').val(data[0].meaning);
                            $('#account_form_view #status_v').val(data[0].status_meaning);
                            $('#account_form_view #meterseq').val(data[0].meter_seq);
                            $('#account_form_view #acctname').val(data[0].acct_name);
                            $('#account_form_view #acctnum').val(data[0].acct_num);
                            $('#account_form_view #activestart').val(data[0].active_start_f);
                            $('#account_form_view #billtoaddr').val(data[0].bill_to_addr_meaning);
                            $('#account_form_view #activeend').val(data[0].active_end_f);
                            $('#account_form_view #attentionto').val(data[0].attention_to);
                            getZones(data[0].entity_id,data[0].acct_addr);
                        },
                        complete: function() {
                            $('#account_v .modal-body').show();
                            $('#loading_account').hide();
                        },
                        beforeSend: function(){
                            $('#account_v .modal-body').hide();
                           $('#loading_account').show();
                        }
                    });
                    $.ajax({
                        url: "<?php echo base_url($this->session->userdata('forajax') . '/get_device'); ?>",
                        method:'post',
                        data: {'account_id': acct_id},
                        dataType:'json',
                        success: function (data) {
                            var tmp = ''
                            var count = 1;
                            $.each(data, function(i, item) {
                                 tmp += "<tr><td>"+count+"</td><td style='display:none;' id='dev_id'>"+data[i].device_assignment_id+"</td><td>"+data[i].device_id+"</td><td>"+data[i].model_number+"</td><td>"+data[i].serial_number+"</td><td>"+data[i].dev_stat_meaning+"</td><td><button class='btn btn-sm btn-outline btn-info btn-xs view-dev-modal'><i class='fa fa-file-text-o fa-lg'></i></button></td><tr>";
                                 count++;
                            });
                            $('#device_table').html(tmp);
                        },
                        complete: function() {
                        },
                        beforeSend: function(){
                        }
                    });
                    $.ajax({
                        url: '<?php echo base_url($this->session->userdata("forajax")); ?>/get_chglist',
                        method: 'POST',
                        data: { 'account_id':  acct_id },
                        dataType: 'json',
                        success: function(data){
                            console.log(data.length);
                            if(data.length !== 0){
                                $('#chglistform_add').hide();
                                var tmp = '';
                                var state = '';
                                $.each(data, function(i,item){
                                    if(data[i].enable_flag == 'Y'){
                                        state = 'checked';
                                    }
                                    tmp += "<tr id='rmv_chglist_add'><td style='display:none;' id='acct_chrg_id_v'>"+ data[i].acct_chrglst_id +"</td><td style='display:none;' id='enable_flag_v'>"+ data[i].enable_flag +"</td><td style='display:none;' id='list_id_v'>"+ data[i].list_id +"</td><td id='list_name_v'>"+ data[i].list_name +"</td><td align='right' id='start_date_v'>"+ data[i].start_date +"</td><td align='right' id='end_date_v'>"+ data[i].end_date +"</td><td align='center'><div class='state icheckbox_square-green "+state+"'></div></tr>";
                                    //$('.chg-list option[value='+data[i].list_id +']').remove();
                                });
                                $('#charglist_tbl').html(tmp);
                                //getchglistadd2();
                            }else{
                                $('#chglistform').show();
                            }
                            //$(".chg-list").trigger("chosen:updated");
                            $('input').iCheck('update');
                        }
                    });
                });

            $(document).on('click','.view-dev-modal',function(){
               $('#device_windowv').show();
               $('#account_windowv').hide();
                var dev_id = $(this).closest('tr').children('#dev_id').text();
                $.ajax({
                    url: "<?php echo base_url($this->session->userdata('forajax') . '/get_device2'); ?>",
                    method:'post',
                    data: {'device_assignment_id': dev_id },
                    dataType:'json',
                    success: function (data) {
                        $('#device_form_v input[name=account_id]').val(data[0].account_id);
                        $('#device_form_v input[name=dev_id]').val(data[0].device_id);
                        $('#device_form_v input[name=item_num]').val(data[0].item_num);
                        $('#device_form_v input[name=dev_type]').val(data[0].dev_type_meaning);
                        $('#device_form_v input[name=model_number]').val(data[0].model_number);
                        $('#device_form_v input[name=serial_number]').val(data[0].serial_number);
                        $('#device_form_v input[name=install_date]').val(data[0].install_date);
                        $('#device_form_v input[name=warranty_per]').val(data[0].warranty_period);
                        $('#device_form_v input[name=initial_read]').val(data[0].initial_reading);
                        $('#device_form_v input[name=last_read]').val(data[0].last_reading);
                        $('#device_form_v input[name=maint_cycle]').val(data[0].maintenance_cycle + " " + data[0].mcu_meaning);
                        $('#device_form_v input[name=repl_cycle]').val(data[0].replacement_cycle + " " + data[0].rcu_meaning);
                        $('#device_form_v input[name=status]').val(data[0].dev_stat_meaning);
                        $('#device_form_v input[name=dev_remarks]').val(data[0].device_remarks);
                    },
                    complete: function() {
                    },
                    beforeSend: function(){
                    }
                });
            });

            function getZones(eid,aid){
                 $.ajax({
                        url: "<?php echo base_url($this->session->userdata('forajax') . '/get_zones'); ?>",
                        method:'post',
                        data: { 'entity_id': eid, 'addr_code': aid },
                        dataType:'json',
                        success: function (data) {
                            $('#account_form_view #z1').val(data[0].zone_1);
                            $('#account_form_view #z2').val(data[0].zone_2);
                            $('#account_form_view #z3').val(data[0].zone_3);
                            $('#account_form_view #z4').val(data[0].zone_4);
                            $('#account_form_view #z5').val(data[0].zone_5);
                        },
                        complete: function() {
                        },
                        beforeSend: function(){
                        }
                    });
            }

            $(document).on({'show.bs.modal': function () {
                    var zIndex = 1040 + (10 * $('.modal:visible').length);
                    $(this).css('z-index', zIndex);
                    setTimeout(function() {
                        $('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack');
                    }, 0);
                }, 'hidden.bs.modal': function() {
                    if ($('.modal:visible').length > 0) {
                        // restore the modal-open class to the body element, so that scrolling works
                        // properly after de-stacking a modal.
                        setTimeout(function() {
                            $(document.body).addClass('modal-open');
                        }, 0);
                    }
                }
            }, '.modal');
            });
    </script>